// src/models/musicPlayerModel.tsx
import { message } from "antd";
import { createRef, useCallback, useEffect, useRef, useState } from "react";
import ReactHowler from "react-howler";

 

export default  function Page() {
  

  const [first,setFirst] = useState(true);
  const [songs,setSongs] = useState<API.SongVO[]>([]);
  const [playing, setPlaying] = useState(false);

 
  const [currentSong, setCurrentSong] = useState<API.SongVO>({});
  const [currentSongIndex, setCurrentSongIndex] = useState(0);


  const AddSong = (song :API.SongVO) =>{
    console.log("song may be added : "+JSON.stringify(song));
    console.log("before add length: "+ songs.length);
    console.log("first: "+ first);
    if(first) {
      songs.push(song);
      setFirst(false);
    } else {
      if(songs.find(item => item.id==song.id)) {
        message.info('该歌曲已添加!');
      } else {
        songs.push(song);
      }
    }
    console.log("now length: "+ songs.length);
  };

  return {
    first,

    songs,
    setSongs,
    AddSong,

    playing,
    setPlaying,

    currentSong,
    setCurrentSong,

    currentSongIndex,
    setCurrentSongIndex,

  };
};